package com.hspedu.newData.dmsxl.哈希表;

import org.junit.Test;

import java.util.HashMap;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-04-22 
 * @Version: 1.0
 */

public class LC454四数相加Ⅱ {

    // 两两分组实现
    public int fourSumCount(int[] nums1, int[] nums2, int[] nums3, int[] nums4) {

        HashMap<Integer, Integer> map1 = new HashMap<>();
        for (int i : nums1) {
            for (int i1 : nums2) {
                map1.put(i + i1,map1.getOrDefault(i+i1,0) + 1);
            }
        }
        HashMap<Integer, Integer> map2 = new HashMap<>();
        for (int i : nums3) {
            for (int i1 : nums4) {
                map2.put(i + i1,map2.getOrDefault(i+i1,0) + 1);
            }
        }
        int count = 0;

        for (Integer i : map1.keySet()) {
            if (map2.containsKey(-i)){
                count += map2.get(-i)*map1.get(i);
            }
        }
        return count;
    }


    @Test
    public void test() {
        // 测试代码
        fourSumCount(new int[]{0},new int[]{0},new int[]{0},new int[]{0});
    }
}
